package com.mlm.mlmapp.activity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
import com.androidquery.util.Constants;
import com.flyco.tablayout.view.OrderFragment;
import com.mlm.mlmapp.R;
import com.mlm.mlmapp.adapter.view.OrderDialog;
import com.mlm.mlmapp.adapter.view.PaymentCancelDialog;
import com.mlm.mlmapp.adapter.view.listener.DialogListener;
import com.mlm.mlmapp.cons.HTTPCons;
import com.mlm.mlmapp.interfaces.Prefs_;
import com.mlm.mlmapp.utils.CommonUtils;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.Receiver;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.ColorRes;
import org.androidannotations.annotations.res.DrawableRes;
import org.androidannotations.annotations.res.StringRes;
import org.androidannotations.annotations.sharedpreferences.Pref;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;


/**
 * Activity which displays a login screen to the user, offering registration as
 * well.
 */
@EActivity(R.layout.payment_detail)
public class OrderDetailActivity extends BaseActivity implements HTTPCons {
    public static final int STATUS_NONPAY = 1;
    public static final int STATUS_BOOKED_PROCEED = 2;
    public static final int STATUS_PAYMENT_SUCCESS = 3;
    public static final int STATUS_BOOKED = 4;
    public static final int STATUS_REPUND = 7;
    public static final int STATUS_CONFIRM = 5;
    public static final int STATUS_FINISH = 6;
    public static final int STATUS_REFUND_FINISH = 11;
    public static final int STATUS_CLOSE = 8;
    AQuery aq;
    AjaxCallback<JSONObject> getPaymentInfoCB;
    PaymentCancelDialog dia;
    @StringRes
    String money;
    @Pref
    Prefs_ pref;
    @Extra
    String orderid;
    @ViewById
    ImageView btn_headimg;
    @ViewById
    TextView tv_dresser;
    @ViewById
    Button tv_post;
    @ViewById
    Button btn_cancel;
    @ViewById
    LinearLayout items;
    @ViewById
    Button btn_date;
    @ViewById
    Button btn_studio;
    @ViewById
    LinearLayout btn_back;
    @ViewById
    Button btn_coupon;
    @ViewById
    TextView tv_money;
    @ViewById
    TextView btn_next;
    @ViewById
    Button btn_username;
    @ViewById
    Button btn_total;
    @ViewById
    Button btn_points;
    @ViewById
    RelativeLayout coupon;
    @ViewById
    RelativeLayout rl_points;
    @ViewById
    CheckBox btn_money;
    @ViewById
    Button btn_paymoney;
    @ViewById
    TextView tv_dingjin1;
    @ViewById
    TextView tv_dingjin3;
    @ViewById
    RelativeLayout dingjin;
    @ViewById
    TextView tv_calc;
    @ViewById
    Button dingjin_icon;
    @ViewById
    TextView tv_status;
    @ViewById
    TextView tv_money_1;
    LayoutInflater inflater;
    @ColorRes
    int red;
    @ColorRes
    int blacktext;
    @ColorRes
    int greyborder;
    @ColorRes
    int lightgreytext;
    @DrawableRes
    Drawable red_edge_btn_long;
    private int total = 0;
    int realMoney;
    int payMoney;
    String depFund;
    OrderDialog refund;
    OrderDialog confirm;
    OrderDialog pay;
    OrderDialog cancel;
    @ViewById
    TextView tv_title;

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent); // 这一句必须的，否则Intent无法获得最新的数据
        this.orderid = intent.getStringExtra("orderid");
        getOrderInfo();
        // api = WXAPIFactory.createWXAPI(this, "wxb4ba3c02aa476ea1");
    }

    @AfterViews
    void init() {
        // api = WXAPIFactory.createWXAPI(this, "wxb4ba3c02aa476ea1");


        aq = new AQuery(this);
        inflater = LayoutInflater.from(this);


//        tv_money.setText(getString(R.string.money, total));
        getPaymentInfoCB = new AjaxCallback<JSONObject>() {

            @Override
            public void callback(String url, JSONObject html, AjaxStatus status) {
                if (status.getCode() == -101) {
                    Toast.makeText(aq.getContext(), "网络异常,请检查网络",
                            Toast.LENGTH_SHORT);
                    return;
                }
                if (status.getCode() == -103) {
                    Toast.makeText(aq.getContext(), "用户信息异常，请联系客服",
                            Toast.LENGTH_SHORT).show();
                } else {
                    if (status.getCode() != 200) {
                        Toast.makeText(aq.getContext(),
                                "网络异常:" + status.getCode(), Toast.LENGTH_SHORT)
                                .show();
                    } else {
                        try {
                            onSuccess(html);
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
            }
        };
        getOrderInfo();
    }


    /**
     * send sms authcode request
     *
     * @throws UnsupportedEncodingException
     */
    private void getOrderInfo() {
        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("mobile", pref.loginID().get()));
        pairs.add(new BasicNameValuePair("orderId", orderid));
        CommonUtils
                .postRequest(get_payment_action, aq, getPaymentInfoCB, pairs);
    }

    private void cancelOrderInfo() {
        AjaxCallback<JSONObject> cancelCallback = new AjaxCallback<JSONObject>() {

            @Override
            public void callback(String url, JSONObject html, AjaxStatus status) {
                if (status.getCode() == -101) {
                    Toast.makeText(aq.getContext(), "网络异常,请检查网络",
                            Toast.LENGTH_SHORT);
                    return;
                }
                if (status.getCode() == -103) {
                    Toast.makeText(aq.getContext(), "用户信息异常，请联系客服",
                            Toast.LENGTH_SHORT).show();
                } else {
                    if (status.getCode() != 200) {
                        Toast.makeText(aq.getContext(),
                                "网络异常:" + status.getCode(), Toast.LENGTH_SHORT)
                                .show();
                    } else {

                        try {
                            if (html.getBoolean("isSuccess")) {
                                Toast.makeText(aq.getContext(),
                                        "订单已取消!", Toast.LENGTH_SHORT)
                                        .show();
                                Intent intent = new Intent();
                                intent.setAction(OrderFragment.ORDER_REFRESH_FLAG);
                                intent.putExtra("refreshflag", "0");
                                aq.getContext().sendOrderedBroadcast(intent, null);
//                                BookActivity_.intent(PaymentWaitActivity.this).start();
                                OrderDetailActivity.this.finish();

                            } else {
                                Toast.makeText(aq.getContext(),
                                        html.getString("errors"), Toast.LENGTH_SHORT)
                                        .show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }


                    }
                }
            }
        };

        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("mobile", pref.loginID().get()));
        pairs.add(new BasicNameValuePair("orderId", orderid));
        CommonUtils
                .postRequest(cancel_order, aq, cancelCallback, pairs);
    }

    void onSuccess(JSONObject obj) throws JSONException {
        aq.id(btn_headimg).image(getJsonString(obj, "iconPhotoUrl"), true,
                true, 200, 0, null, Constants.FADE_IN);

        int status = CommonUtils.getJsonInt(obj, "status");
        int refundStatus = CommonUtils.getJsonInt(obj, "refundStatus");
        String isComment = CommonUtils.getJsonString(obj, "isComment");
        String isDepund = CommonUtils.getJsonString(obj, "isDepfund");
        String depFund = CommonUtils.getJsonString(obj, "depFund");
        payMoney = CommonUtils.getJsonInt(obj, "payMoney");
        final String dresserid = CommonUtils.getJsonString(obj, "stylistId");
        if ("2".equals(isDepund)) {
            dingjin_icon.setVisibility(View.VISIBLE);
            dingjin.setVisibility(View.VISIBLE);
            tv_money.setText(getString(R.string.money, Integer.valueOf(depFund)));
        } else {
            tv_money.setText(getString(R.string.money, getJsonInt(obj, "realMoney")));
            dingjin.setVisibility(View.GONE);
        }
        tv_title.setText("订单详情");
        switch (status) {
            //1-未支付
            case STATUS_NONPAY:
                tv_title.setText("待支付");
                btn_next.setText("去支付");
                tv_calc.setText("待支付金额：");
                tv_money.setText(getString(R.string.money, getJsonInt(obj, "payMoney")));
                dingjin.setVisibility(View.VISIBLE);
                tv_status.setVisibility(View.GONE);
                ((ImageButton) btn_back.getChildAt(0)).setImageResource(R.drawable.payment_close);
                btn_cancel.setVisibility(View.VISIBLE);
                btn_next.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PaymentOrderActivity_.intent(OrderDetailActivity.this)
                                .extra("orderid", orderid).start();
                        OrderDetailActivity.this.finish();
                    }
                });
                break;
            //2-支付处理
            case STATUS_BOOKED_PROCEED:
                btn_next.setText("支付处理中");
                break;
            //3- 支付成功
            case STATUS_PAYMENT_SUCCESS:
                tv_status.setText("(已支付)");
                btn_next.setText("退款");

                btn_next.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        refund = new OrderDialog(OrderDetailActivity.this,
                                new DialogListener() {

                                    @Override
                                    public void onCancel() {
                                        // TODO Auto-generated method stub

                                    }

                                    @Override
                                    public void onApply(JSONObject obj,
                                                        String clazz) {
                                        // TODO Auto-generated method stub
                                        refundAction(orderid, CommonUtils
                                                .getJsonString(obj,
                                                        "reason"));
                                        refund.dismiss();
                                    }
                                }, null, "订单退款");
                        refund.show();
//                        OrderDetailActivity.this.finish();
                    }
                });
                break;
            //4-预约成功
            case STATUS_BOOKED:
                tv_status.setText("(预约成功)");
                btn_next.setText("退款");
                btn_next.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        refund = new OrderDialog(OrderDetailActivity.this,
                                new DialogListener() {

                                    @Override
                                    public void onCancel() {
                                        // TODO Auto-generated method stub

                                    }

                                    @Override
                                    public void onApply(JSONObject obj,
                                                        String clazz) {
                                        // TODO Auto-generated method stub
                                        refundAction(orderid, CommonUtils
                                                .getJsonString(obj,
                                                        "reason"));
                                        refund.dismiss();
                                    }
                                }, null, "订单退款");
                        refund.show();
//                        OrderDetailActivity.this.finish();
                    }
                });
                break;
            //8-订单关闭
            case STATUS_CLOSE:
                tv_status.setText("(已取消)");
                btn_next.setText("重新预约");
                btn_next.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        BookActivity_.intent(OrderDetailActivity.this)
                                .extra("id", dresserid).start();
                    }
                });
                break;
            //7-退款
            case STATUS_REPUND:
                // 1-待处理  2-退款成功 3、退款支付处理中 4、退款支付失败
                // 当为1的时候显示“退款审核”
                // 下面有取消退款按钮
                // 当为2的时候显示“退款成功”
                // 下面无取消退款按钮
                // 3 4 的时候 “退款执行” 无取消退款按钮
                dingjin.setVisibility(View.GONE);
                if (refundStatus == 1) {
                    tv_status.setText("(退款审核)");
                    btn_next.setText("取消退款");
                    btn_next.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            // TODO Auto-generated method stub
                            // quxiaotuikuan
                            cancel = new OrderDialog(OrderDetailActivity.this,
                                    new DialogListener() {

                                        @Override
                                        public void onCancel() {
                                            // TODO Auto-generated method stub

                                        }

                                        @Override
                                        public void onApply(JSONObject obj,
                                                            String clazz) {
                                            // TODO Auto-generated method stub
                                            cancelRefundAction(orderid);
                                            cancel.dismiss();
                                        }
                                    }, "是否取消退款？", "温馨提示");
                            cancel.show();
                        }
                    });
                } else if (refundStatus == 2) {
                    tv_status.setText("(退款成功)");
                    btn_next.setVisibility(View.INVISIBLE);
                } else {
                    tv_status.setText("(退款执行)");
                    btn_next.setVisibility(View.INVISIBLE);
                }


                break;
            //5-到店确认
            case STATUS_CONFIRM:
                tv_status.setText("(已消费)");
                btn_next.setText("确认完成");
                btn_next.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // // TODO: 2016/3/24
                        isConfirmOrder(orderid);
                    }
                });
                break;
            //6-订单完成
            case STATUS_FINISH:
                dingjin.setVisibility(View.GONE);
                if ("2".equals(isDepund)) {
                    tv_money_1.setVisibility(View.VISIBLE);
                    tv_money_1.setText(getString(R.string.payadd, getJsonInt(obj, "realMoney") - getJsonInt(obj, "depFund")));
                    if (payMoney != 0) {
                        tv_money.setText(getString(R.string.money, Integer.valueOf(depFund)));
                    }
                }
                if ("0".equals(isComment)) {
                    tv_status.setText("(已完成)");
                    btn_next.setText("去评价");
                    btn_next.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            CommentSubmitActivity_
                                    .intent(OrderDetailActivity.this)
                                    .extra("dresserid", dresserid)
                                    .extra("orderid", orderid)
                                    .startForResult(11);
                        }
                    });

                } else {
                    tv_status.setText("(已完成)");
                    btn_next.setText("查看评价");
                    btn_next.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            MyCommentsListActivity_.intent(OrderDetailActivity.this).start();
                        }
                    });
                }


                break;

            default:
                break;
        }


        btn_paymoney.setText(getString(R.string.pay, getJsonInt(obj, "realMoney")));
        realMoney = getJsonInt(obj, "realMoney");
        depFund = getJsonString(obj, "depFund");
        if ("0".equals(getJsonString(obj, "userCouponId"))) {
            coupon.setVisibility(View.GONE);
        }
        if ("0".equals(getJsonString(obj, "integralMoney"))) {
            rl_points.setVisibility(View.GONE);
        } else {
            btn_points.setText(getString(R.string.money1,
                    getJsonInt(obj, "integralMoney")));
        }
        if ("1".equals(getJsonString(obj, "status"))) {
            btn_cancel.setVisibility(View.VISIBLE);
        } else {
            btn_cancel.setVisibility(View.INVISIBLE);
        }
        btn_coupon.setText(getJsonString(obj, "userCouponName"));
//        btn_points.setText(getJsonString(obj,"userCouponName"));
        btn_username.setText(getJsonString(obj, "userName"));
        btn_date.setText(getJsonString(obj, "appointTimes"));
        tv_dresser.setText(getJsonString(obj, "name"));

        tv_post.setText(getJsonString(obj, "leveName"));
        btn_total.setText(getString(R.string.money,
                getJsonInt(obj, "orderMoney")));

        tv_dingjin1.setText(getString(R.string.pay,
                getJsonInt(obj, "depFund")));
        tv_dingjin3.setText(getString(R.string.pay, getJsonInt(obj, "realMoney") - getJsonInt(obj, "depFund")));

        if ("2".equals(getJsonString(obj, "isDepfund").toString())) {
            btn_money.setClickable(false);
            btn_money.isChecked();
            btn_money.setChecked(true);
        } else {
            dingjin.setVisibility(View.GONE);
        }
        JSONArray array = getJsonArray(obj, "bookProducts");
        items.removeAllViews();
        for (int i = 0; i < array.length(); i++) {
            final JSONObject temp = array.getJSONObject(i);
            if (!temp.isNull("productName")) {
                View view = inflater.inflate(R.layout.payment_group_item, null);
                ((TextView) view.findViewById(R.id.row_group_item))
                        .setText(getJsonString(temp, "productName"));
                ((TextView) view.findViewById(R.id.row_price))
                        .setText(getString(R.string.money,
                                getJsonInt(temp, "price")));
                items.addView(view);
            }
        }
        JSONObject studio = getJsonObject(obj, "studio");
        btn_studio.setText(getJsonString(studio, "names"));
    }

    @Click
    void btn_cancel() {
        dia = new PaymentCancelDialog(this, new DialogListener() {
            @Override
            public void onApply(JSONObject obj, String clazz) {
                cancelOrderInfo();
                dia.dismiss();

            }

            @Override
            public void onCancel() {

            }
        });
        dia.show();
    }

    @Click
    void btn_money() {
        if (btn_money.isChecked()) {
            tv_money.setText(getString(R.string.pay, Integer.valueOf(depFund)));
        } else {
            tv_money.setText(getString(R.string.pay, Integer.valueOf(realMoney)));
        }
    }

//    @Click
//    void btn_next() {
//        PaymentOrderActivity_.intent(OrderDetailActivity.this)
//                .extra("orderid", orderid).start();
//        this.finish();
//    }

    @Click
    void btn_back() {
        onBackPressed();
    }

    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        Intent data = new Intent();
        setResult(RESULT_CANCELED, data);
        this.finish();
    }

    void refundAction(String orderid, String reason) {

        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("mobile", pref.loginID().get()));
        pairs.add(new BasicNameValuePair("orderId", orderid));
        pairs.add(new BasicNameValuePair("reason", reason));

        CommonUtils.postRequest(HTTPCons.refund_order, aq,
                new AjaxCallback<JSONObject>() {

                    @Override
                    public void callback(String url, JSONObject object,
                                         AjaxStatus status) {
                        // TODO Auto-generated method stub
                        super.callback(url, object, status);
                        if (status.getCode() == -101) {
                            Toast.makeText(aq.getContext(), "网络异常,请检查网络",
                                    Toast.LENGTH_SHORT);
                            return;
                        }
                        if (status.getCode() == 200) {
                            try {
                                if (object.getBoolean("isSuccess")) {
                                    Toast.makeText(aq.getContext(),
                                            "退款申请发送成功",
                                            Toast.LENGTH_SHORT).show();
                                    OrdersActivity_.intent(aq.getContext()).flags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT).start();
//                                    Intent intent = new Intent();
//                                    intent.setAction(ORDER_REFRESH_FLAG);
//                                    intent.putExtra("refreshflag", "0");
//                                    getContext().sendOrderedBroadcast(intent, null);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Toast.makeText(aq.getContext(),
                                    "网络异常:" + status.getCode(),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }

                }, pairs);
    }

    void isConfirmOrder(final String orderid) {
        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("mobile", pref.loginID().get()));
        pairs.add(new BasicNameValuePair("orderId", orderid));
        CommonUtils.postRequest(HTTPCons.isconfirm_order, aq,
                new AjaxCallback<JSONObject>() {

                    @Override
                    public void callback(String url, JSONObject object,
                                         AjaxStatus status) {
                        // TODO Auto-generated method stub
                        super.callback(url, object, status);
                        if (status.getCode() == -101) {
                            Toast.makeText(aq.getContext(), "网络异常,请检查网络",
                                    Toast.LENGTH_SHORT);
                            return;
                        }
                        if (status.getCode() == 200) {
                            try {
                                if (object.getBoolean("isSuccess")) {
                                    Toast.makeText(aq.getContext(),
                                            "确认订单状态",
                                            Toast.LENGTH_SHORT);
                                    show(String.valueOf(object.getJSONArray("errors").getInt(0)), orderid);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Toast.makeText(aq.getContext(),
                                    "网络异常:" + status.getCode(),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }

                }, pairs);
    }

    private void show(String errors, final String orderid) {
        if ("1".equals(errors)) {
            pay = new OrderDialog(OrderDetailActivity.this,
                    new DialogListener() {

                        @Override
                        public void onCancel() {
                        }

                        @Override
                        public void onApply(JSONObject obj,
                                            String clazz) {
                            PaymentWaitActivity_.intent(aq.getContext()).extra("orderid", orderid).extra("mymoney", realMoney - payMoney).start();
                            pay.dismiss();
                        }
                    }, "是否确认完成并支付尾款？", "温馨提示");
            pay.show();
        } else {
            confirm = new OrderDialog(OrderDetailActivity.this,
                    new DialogListener() {

                        @Override
                        public void onCancel() {
                        }

                        @Override
                        public void onApply(JSONObject obj,
                                            String clazz) {
                            submitAction(orderid);
                            confirm.dismiss();
                        }
                    }, "是否确认完成订单？", "温馨提示");
            confirm.show();
        }
    }

    void submitAction(String orderid) {
        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("mobile", pref.loginID().get()));
        pairs.add(new BasicNameValuePair("orderId", orderid));
        CommonUtils.postRequest(HTTPCons.confirm_order, aq,
                new AjaxCallback<JSONObject>() {

                    @Override
                    public void callback(String url, JSONObject object,
                                         AjaxStatus status) {
                        // TODO Auto-generated method stub
                        super.callback(url, object, status);
                        if (status.getCode() == -101) {
                            Toast.makeText(aq.getContext(), "网络异常,请检查网络",
                                    Toast.LENGTH_SHORT);
                            return;
                        }
                        if (status.getCode() == 200) {
                            try {
                                if (object.getBoolean("isSuccess")) {
                                    Toast.makeText(aq.getContext(),
                                            "确认订单成功",
                                            Toast.LENGTH_SHORT);
                                    OrdersActivity_.intent(aq.getContext()).flags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT).start();

//                                    Intent intent = new Intent();
//                                    intent.setAction(ORDER_REFRESH_FLAG);
//                                    intent.putExtra("refreshflag", "0");
//                                    getContext().sendOrderedBroadcast(intent, null);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Toast.makeText(aq.getContext(),
                                    "网络异常:" + status.getCode(),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }

                }, pairs);
    }

    void cancelRefundAction(String orderid) {

        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("mobile", pref.loginID().get()));
        pairs.add(new BasicNameValuePair("orderId", orderid));

        CommonUtils.postRequest(HTTPCons.cancel_refund_order, aq,
                new AjaxCallback<JSONObject>() {

                    @Override
                    public void callback(String url, JSONObject object,
                                         AjaxStatus status) {
                        // TODO Auto-generated method stub
                        super.callback(url, object, status);
                        if (status.getCode() == -101) {
                            Toast.makeText(aq.getContext(), "网络异常,请检查网络",
                                    Toast.LENGTH_SHORT);
                            return;
                        }
                        if (status.getCode() == 200) {
                            try {
                                if (object.getBoolean("isSuccess")) {
                                    Toast.makeText(aq.getContext(),
                                            "取消退款成功",
                                            Toast.LENGTH_SHORT).show();
                                    OrdersActivity_.intent(aq.getContext()).flags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT).start();
//                                    Intent intent = new Intent();
//                                    intent.setAction(ORDER_REFRESH_FLAG);
//                                    intent.putExtra("refreshflag", "0");
//                                    getContext().sendOrderedBroadcast(intent, null);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else {
                            Toast.makeText(aq.getContext(),
                                    "网络异常:" + status.getCode(),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }

                }, pairs);
    }

    @Receiver(actions = OrderFragment.ORDER_REFRESH_FLAG)
    protected void onOrderRefresh(Intent intent) {
        Intent intent1 = new Intent();
        intent1.setAction(OrderFragment.ORDER_REFRESH_FLAG);
        aq.getContext().sendOrderedBroadcast(intent1, null);
        OrderDetailActivity.this.finish();
    }
}
